package com.cloud.hyworkday;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
public class HYController {

    @RequestMapping(value = "/isWorkDay")
     public Map isWorkDay(@RequestParam("strHDate") String strHDate, @RequestParam("strDate")String strDate, @RequestParam("forDays")int forDays){
        Calendar calendar1 = Calendar.getInstance();
        calendar1.set(Integer.parseInt(strHDate.split("-")[0]),Integer.parseInt(strHDate.split("-")[1])-1,Integer.parseInt(strHDate.split("-")[2]));
        Calendar calendar2 = Calendar.getInstance();
        calendar2.set(Integer.parseInt(strDate.split("-")[0]),Integer.parseInt(strDate.split("-")[1])-1,Integer.parseInt(strDate.split("-")[2]));
        long mss = calendar2.getTime().getTime() - calendar1.getTime().getTime();
        long days = mss / (1000 * 60 * 60 * 24);
        long l = days % forDays;
        String b="不知道";
        if (l==0) b="休假";
        else      b="上班";
        System.out.println(calendar2.get(Calendar.YEAR)+"-"+(calendar2.get(Calendar.MONTH)+1)+"-"+calendar2.get(Calendar.DATE)+"    "
                +"相差"+days+"天"+"    "+b);
        Map<String, String> map = new HashMap<>();
        map.put("code","1");
        map.put("info","成功");
        map.put("data",b);
        return map;
     }
}
